#!/usr/bin/perl

package CMUD::Authenticate;

use strict;
use warnings;

use Digest::MD5 qw( md5_hex );
use DBH;

use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
require Exporter;

@ISA = qw( Exporter AutoLoader );
@EXPORT = qw();
$VERSION = '0.01';

sub authenticate_user {
  my $username = shift;
  my $password = shift;
  
  $username = valid_username( $username ) || die "Please play nice with the System";
  $password = md5_hext( $password );
  
  my $user_auth_token = gen_auth_token( $username, $password );
  return 'true' if $user_auth_token;
  return 0;
}

sub gen_auth_token {
  my $username = shift;
  my $password = shift;
  
  my $user = select_authentication( $username, $password ) || return 0;
  #do voodoo here
}

sub valid_username { 
  my $username = shift;
  return $username if $username =~ m/^[a-zA-Z0-9_ ]+$/;
  return 0;
}

1;
__END__
